package com.grape.dp.observer.simple;
import java.util.ArrayList;
import java.util.List;

/**
 * 描述:WeChatSubject
 * @author: myx
 * @date: 2019/7/29 0029
 * Copyright © 2019-grape. All rights reserved.
 */
public class WeChatSubject implements AbstractSubject {
    /**
     * 如何存放这些主题
     * @param obServer
     */
    private List<ObServer> obServerList = new ArrayList<ObServer>();
    public void addObServer(ObServer obServer) {
        // 注册或者添加观察者
        obServerList.add(obServer);
    }

    public void removeServer(ObServer obServer) {
        obServerList.remove(obServer);
    }
    public void notifyObServer(String message) {
        System.out.println("开始设置微信群发消息：" + message);
        // 调用观察者通知方案
        for (int i = 0; i < obServerList.size(); i++) {
            ObServer obServer = obServerList.get(i);
            // 调用该方法通知 获取具体的消息  群发
            obServer.update(message);
        }
    }
}
